// 这里是将我们的请求函数进行二次封装 在这里我们封装好每一个接口的请求函数
import request from '@utils/request'

// 请求商品分类 定义一个函数
const fetchCates = (params = {}) => request.get('/shop/goods/category/all', {
  params
})
// 请求banner轮播数据
const fetchHomeBanner = (params = {}) => request.get('/banner/list', {
  params
})
// 请求分类商品数据
const fetchHomeList = (params = {}) => request.post('/shop/goods/list/v2', params)

// 请求商品商品详情数据 要传一个id
const fetchItemDetail = (id) => request.get('/shop/goods/detail', {
  params: {
    id
  }
})
// 加入购物车
const addCart = (params = {}) => request.post('/shopping-cart/add', params)
// 注册
const register = (params = {}) => request.post('/user/username/register', params)
// 登录
const doLogin = (params = {}) => request.post('/user/username/login', params)
// 请求购物车数据
const cartInfo = (params = {}) => request.get('/shopping-cart/info', {
  params
})
// 修改购物车的购买商品数量
const setCartNum = (params = {}) => request.post('/shopping-cart/modifyNumber', params)
// 删除购物车的某条商品
const delCartItem = (params = {}) => request.post('/shopping-cart/remove', params)
// 修改购物车的选中状态
const cartItemSelected = (params = {}) => request.post('/shopping-cart/select', params)
// 添加收获地址
const addContact = (params = {}) => request.post('/user/shipping-address/add', params)
// 获取收货人地址列表
const contactList = (params = {}) => request.post('/user/shipping-address/list/v2', params)
// 编辑收获地址
const updateContact = (params = {}) => request.post('/user/shipping-address/update', params)
// 获取收获地址的信息
const fetchContactInfo = (params = {}) => request.get('/user/shipping-address/detail/v2', {
  params
})
// 删除收货地址
const delContact = (params = {}) => request.post('/user/shipping-address/delete', params)
// 获取默认收货地址
const fetchDefaultContact = (params = {}) => request.get('/user/shipping-address/default/v2', {
  params
})

export {
  fetchCates,
  fetchHomeBanner,
  fetchHomeList,
  fetchItemDetail,
  addCart,
  register,
  doLogin,
  cartInfo,
  setCartNum,
  delCartItem,
  cartItemSelected,
  addContact,
  contactList,
  updateContact,
  fetchContactInfo,
  delContact,
  fetchDefaultContact
}
